<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      'use strict';
      const user = {
        name: 'jack',
        loginOk() {
          console.log(`${this.name} 登录成功`);
        },
        loginFail() {
          console.log(`${this.name} 登录失败`);
        },
      };

      function askPassword(ok, fail) {
        // ok=user.loginOk fail = user.loginFail
        const password = prompt('请输入密码？');
        if (password === '123123') {
          ok();
        } else {
          fail();
        }
      }
      askPassword(user.loginOk.bind(user), user.loginFail.bind(user));
      /*
        this 指向调用他的对象
        this 的值都是在运行时候被确定
      */
      // user.loginOk();
      // user.loginFail();
    </script>
  </body>
</html>
